home *** CD-ROM | disk | FTP | other *** search
/ .net (French) 1996 December / .net Magazine (FR) - Issue 02 - Dec 1996.iso / Utilpers / SUPERQUE / DATA.2 / FILTERS / PSINIT / GS_DPS1.PS < prev    next >
Text File  |  1995-11-15  |  6KB  |  213 lines

  1. %    Copyright (C) 1990, 1991, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2. %    Licensed to Zenographics Inc. (Irvine, California) by Artifex Software Inc.
  3. %    under the OEM Agreement of December 21st, 1993.
  4.  
  5. % Initialization file for analogs of Display PostScript functions
  6. % that are also included in Level 2.
  7. % When this is run, systemdict is still writable,
  8. % but (almost) everything defined here goes into level2dict.
  9.  
  10. level2dict begin
  11.  
  12. % ------ Virtual memory ------ %
  13.  
  14. /currentshared /.currentglobal load def
  15. /scheck /.gcheck load def
  16. %****** FOLLOWING IS WRONG ******
  17. /shareddict currentdict /globaldict .knownget not { 20 dict } if def
  18.  
  19. % Global and LocalFontDirectory must remain in systemdict
  20. % even if we temporarily exit Level 2 mode.
  21.  
  22. end                % level2dict
  23. systemdict begin
  24.  
  25. /SharedFontDirectory FontDirectory .gcheck
  26.  { .currentglobal false .setglobal
  27.    /LocalFontDirectory FontDirectory dup maxlength dict copy def
  28.    .setglobal FontDirectory
  29.  }
  30.  { /LocalFontDirectory FontDirectory def
  31.    50 dict
  32.  }
  33. ifelse def
  34.  
  35. end                % systemdict
  36. level2dict begin
  37.  
  38. % setshared must rebind FontDirectory to the appropriate one of
  39. % Local or SharedFontDirectory.
  40.  
  41. /.setglobal
  42.  { .setglobal
  43.    //systemdict /FontDirectory .currentglobal
  44.     { //SharedFontDirectory }
  45.     { //systemdict /LocalFontDirectory get }    % can't embed ref to local VM
  46.    ifelse .forceput
  47.  } .bind odef        % must bind .forceput and .setglobal
  48.             % even if NOBIND in effect
  49. /setshared /.setglobal load def
  50. .currentglobal setshared
  51.  
  52. % ------ Fonts ------ %
  53.  
  54. /selectfont
  55.  { exch findfont exch
  56.    dup type /arraytype eq { makefont } { scalefont } ifelse
  57.    setfont
  58.  } odef
  59. % Undefinefont has to take local/global VM into account.
  60. /undefinefont
  61.  { FontDirectory 1 index undef
  62.    .currentglobal
  63.     {        % Current mode is global; delete from local directory too.
  64.       systemdict /LocalFontDirectory .knownget
  65.        { exch undef }
  66.        { pop }
  67.       ifelse
  68.     }
  69.     {        % Current mode is local; if there was a shadowed global
  70.         % definition, copy it into the local directory.
  71.       systemdict /SharedFontDirectory .knownget
  72.        { 1 index .knownget
  73.       { FontDirectory 3 1 roll put }
  74.       { pop }
  75.      ifelse
  76.        }
  77.       if
  78.     }
  79.    ifelse
  80.  } odef
  81.  
  82. % If we load a font into global VM within an inner save, the restore
  83. % will delete it from FontDirectory but not from SharedFontDirectory.
  84. % We have to handle this by making restore copy missing entries from
  85. % SharedFontDirectory to FontDirectory.  Since this could slow down restore
  86. % considerably, we define a new operator .dictcopynew for this purpose.
  87. /restore
  88.  { //restore
  89.    //SharedFontDirectory //systemdict /LocalFontDirectory get .dictcopynew pop
  90.  } bind odef
  91.  
  92. % ------ Halftones ------ %
  93.  
  94. /.makestackdict
  95.     { { counttomark -1 roll } forall .dicttomark
  96.     } bind def
  97. /currenthalftone
  98.     { mark .currenthalftone
  99.        { { exch pop }        % halftone
  100.          { /HalftoneType 1        % screen
  101.         { /Frequency /Angle /SpotFunction }
  102.            .makestackdict
  103.          }
  104.          { /HalftoneType 2        % colorscreen
  105.         { /RedFrequency /RedAngle /RedSpotFunction
  106.           /GreenFrequency /GreenAngle /GreenSpotFunction
  107.           /BlueFrequency /BlueAngle /BlueSpotFunction
  108.           /GrayFrequency /GrayAngle /GraySpotFunction
  109.         }
  110.            .makestackdict
  111.          }
  112.        }
  113.       exch get exec
  114.     } odef
  115. % Define sethalftone so it converts all other types to type 5.
  116. /.sethalftoneRGBV    % <dict> <type> <keys> <keysRGBV>
  117.     { 4 -1 roll exch { 1 index exch get exch } forall 15 1 roll
  118.       14 -2 roll mark 15 1 roll { /Gray /Blue /Green /Red }
  119.        {        % stack: v0 v1 v2 type keys comp
  120.          mark
  121.          2 index 0 get 8 -1 roll
  122.          4 index 1 get 9 -1 roll
  123.          6 index 2 get 10 -1 roll
  124.             % stack: type keys comp mark k0 v0 k1 v1 k2 v2
  125.          /HalftoneType 10 index .dicttomark
  126.          counttomark 2 roll
  127.        }
  128.       forall pop pop
  129.       /Default 1 index .dicttomark .sethalftone5
  130.     } bind def
  131. /sethalftone
  132.     { dup /HalftoneType get 1 sub
  133.        {  { mark /Default 2 index .dicttomark .sethalftone5 }
  134.           { 1 { /Frequency /Angle /SpotFunction }
  135.         { /RedFrequency /RedAngle /RedSpotFunction
  136.           /GreenFrequency /GreenAngle /GreenSpotFunction
  137.           /BlueFrequency /BlueAngle /BlueSpotFunction
  138.           /GrayFrequency /GrayAngle /GraySpotFunction
  139.         } .sethalftoneRGBV
  140.           }
  141.           { mark /Default 2 index .dicttomark .sethalftone5 }
  142.           { 3 { /Width /Height /Thresholds }
  143.         { /RedWidth /RedHeight /RedThresholds
  144.           /GreenWidth /GreenHeight /GreenThresholds
  145.           /BlueWidth /BlueHeight /BlueThresholds
  146.           /GrayWidth /GrayHeight /GrayThresholds
  147.         } .sethalftoneRGBV
  148.           }
  149.           { dup .sethalftone5 }
  150.        } exch get exec
  151.     } odef
  152. % Redefine setscreen and setcolorscreen to recognize halftone dictionaries.
  153. /setscreen
  154.     { dup type /dicttype eq
  155.        { sethalftone pop pop }
  156.        { //setscreen }
  157.       ifelse
  158.     } odef
  159. /setcolorscreen
  160.     { dup type /dicttype eq
  161.        { sethalftone 11 { pop } repeat }
  162.        { //setcolorscreen }
  163.       ifelse
  164.     } odef
  165.  
  166. % ------ User objects ------ %
  167.  
  168. /.localarray where
  169.  { pop }
  170.  { /.localarray
  171.     { currentglobal false setglobal
  172.       exch array exch setglobal
  173.     } bind def
  174.  }
  175. ifelse
  176. /defineuserobject
  177.     { userdict /.UserObjects known
  178.        { 1 index userdict /.UserObjects get length ge
  179.           { 1 index 1 add .localarray userdict /.UserObjects get
  180.         1 index copy pop
  181.         userdict /.UserObjects 3 -1 roll put
  182.           }
  183.          if
  184.        }
  185.        { userdict /.UserObjects 3 index 1 add .localarray put
  186.        }
  187.       ifelse
  188.       userdict /.UserObjects get 3 1 roll put
  189.     } odef
  190. /execuserobject
  191.     { userdict /.UserObjects get exch get exec
  192.     } odef
  193. /undefineuserobject
  194.     { userdict /.UserObjects get exch null put
  195.     } odef
  196.  
  197. % ------ User paths ------ %
  198.  
  199. /upath
  200.     { [ exch {/ucache cvx} if pathbbox /setbbox cvx
  201.       {/moveto cvx} {/lineto cvx} {/curveto cvx} {/closepath cvx}
  202.       pathforall ] cvx
  203.     } odef
  204.  
  205. % Dummy definitions for cache control operators
  206.  
  207. /ucachestatus
  208.     { mark 0 0 0 0 0 } odef
  209. /setucacheparams
  210.     { cleartomark } odef
  211.  
  212. end                % level2dict
  213.